﻿
@{ 

    var user = ViewData["User"] as BaseAuthRole.DTO.User.UUIUser;

    var app = ViewData["App"] as BaseAuthRole.DTO.Auth.ApplicationModel;

    var scope_name_list = ViewData["ScopeNameList"] as List<string>;

    var publicAppAuthorizeIput=ViewData["PublicAppAuthorizeIput"] as BaseAuthRole.Domain.Input.PublicAppAuthorizeIput;

}

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>授权</title>
    <link href="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Resource/css/style.css" rel="stylesheet" />
    <link href="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Resource/js/vendor/toastr/toastr.min.css" rel="stylesheet" />
</head>
<body>
    <div class="login_bg">
        @*<img src="/Resource/img/logo.png" class="logo">*@
        <div class="authorization_box center">
            <div class="title">服务授权</div>
            <div class="flex mt-96">
                <div class="left-icon">
                    <div class="ml-145 text-center gap">
                        <P class="tip1">通过登录并授权，<span>@app.Name</span>应用获取你的部分个人信息</P>
                        <img src="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Resource/img/user.png" class="user-img">
                        <p class="user-number"></p>
                        <input type="button" class="authorization" value="授权" onclick="Authorize(this)">
                    </div>
                </div>
                <div class="right-icon">
                    <div class="ml-44 mr-257">
                        <p class="tip2"><span>@app.Name</span>将获得以下权限：</p>
                        @foreach (var o in scope_name_list)
                        {
                            <p class="tip3">- 获得您的@(o)</p>
                        }
                        <p class="tip4">授权后表明你已同意<span>启梦智慧平台服务协议</span></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="footer">
            
        </div>
    </div>
    <script src="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/js/jquery-1.10.2.min.js"></script>
    <script src="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Resource/js/vendor/toastr/toastr.min.js"></script>
    <script src="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Resource/js/Notic.js"></script>

    <script>

        var appid = "@publicAppAuthorizeIput.AppId";

        var scope = "@publicAppAuthorizeIput.Scope";

        var redirect_uri = "@Html.Raw(publicAppAuthorizeIput.RedirectUri)";

        Authorize();

        function Authorize(obj)
        {
            if (obj != null) {
                $(obj).attr("disabled", "disabled");
            }
            $.ajax({
                url: "@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/OAuth2/AuthorizeDo",
                data: { "appid": appid, "scope": scope, "redirectUri": redirect_uri },
                dataType: "json",
                type: "post",
                success: function (data)
                {
                    console.log(data);
                    if (data.IsError)
                    {
                        Notic('error', data.Message);
                    }
                    else {
                        location = data.Result;
                    }

                    if (obj != null)
                    {
                        $(obj).removeAttr("disabled");
                    }
                },
                error: function (data) {


                }
            });
        }


    </script>
</body>
</html>
